# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     conf
   Description :
   Author :       Jolg
   date：          2021/11/4
-------------------------------------------------
   Change Activity:
                   2021/11/4:
-------------------------------------------------
"""

from fastapi import status
from fastapi.responses import JSONResponse, Response, ORJSONResponse
import time
from typing import Union


def success(data: Union[list, dict, str]=None, *, message: str="Success") -> dict:
    return {
        'code': 1,
        'message': message,
        'success': True,
        'data': data,
        'timestamp':time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    }
def fail(data: Union[list, dict, str]=None, *, message: str="Fail") -> dict:
    return {
        'code': 0,
        'message': message,
        'success': False,
        'data': data,
        'timestamp':time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    }

def resp_200(data: Union[list, dict, str]=None, *, message: str="Success") -> dict:
    return {
            'code': 200,
            'message': message,
            'data': data,
        }


def resp_403(data: str = None) -> Response:
    return ORJSONResponse(
        status_code=status.HTTP_403_FORBIDDEN,
        content={
            'code': 403,
            'message': "Forbidden",
            'data': data,
        }
    )


def resp_404(data: str = None) -> Response:
    return ORJSONResponse(
        status_code=status.HTTP_404_NOT_FOUND,
        content={
            'code': 404,
            'message': "Page Not Found",
            'data': data,
        }
    )


def resp_500(data: str = None) -> Response:
    return ORJSONResponse(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        content={
            'code': "500",
            'message': "Server internal error",
            'data': data,
        }
    )


# 自定义
def resp_5000(data: Union[list, dict, str]) -> Response:
    return JSONResponse(
        status_code=status.HTTP_200_OK,
        content={
            'code': 5000,
            'message': "Token failure",
            'data': data,
        }
    )
